package com.java.base.exercise.designmode.single;

/**
 * @Author RenPu
 * @Date 2021/6/21 9:52
 * @Version 1.0
 * @Description:设计模式---单例设计模式V4.0 懒汉式汉式加载  针对使用同步锁的优化，优化颗粒度+双重检测
 **/
public class Single_004 {

    private static volatile Single_004 Instance;

    private Single_004() {
    }


    //使用同步锁，避免线程的问题  DCL(双重校验锁的编写)
    public static Single_004 getInstance() {
        if (Instance == null) {
            synchronized (Single_004.class) {
                if (Instance == null) {
                    Instance = new Single_004();
                }
            }
        }
        return Instance;
    }

}
